package domain;

import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
/**
 * This class contains HTTPDragon's settings.
 * @author HTTPDragon Team
 */
public class ServerConfig {
    private static final Logger logger = Logger.getLogger("HTTPDragon Log");
    private boolean httpRun;
    private String httpRootPath;
    private int httpPort;
    private String httpDefaultPage;  
    private boolean httpsRun;
    private String httpsDefaultPage;
    private String httpsRootPath;
    private int httpsPort;
    private String httpsPrivateKey;
    private boolean phpRun;  
    private String phpPath;

    /**
     * This method returns the HTTPS private key.
     * @return HTTPS private key.
     */
    public String getHttpsPrivateKey() {
        return httpsPrivateKey;
    }

    /**
     * This method sets the HTTPS private key.
     * @param httpsPrivateKey a string containing the private key.
     */
    private void setHttpsPrivateKey(String httpsPrivateKey) {
        this.httpsPrivateKey = httpsPrivateKey;
    }
    
    /**
     * This method determines whether or not the HTTPS module is running.
     * @return boolean
     */
    public boolean isHttpsRun() {
        return httpsRun;
    }

    
    private void setHttpsRun(boolean httpsRun) {
        this.httpsRun = httpsRun;
    }

    /**
     * This method determines whether or not PHP is enabled.
     * @return True or false.
     */
    public boolean isPhpRun() {
        return phpRun;
    }

    private void setPhpRun(boolean phpRun) {
        this.phpRun = phpRun;
    }
    
    /**
     * This method determines whether or not the HTTP module is running.
     * @return True or false.
     */
    public boolean isHttpRun() {
        return httpRun;
    }

    
    private void setHttpRun(boolean httpRun) {
        this.httpRun = httpRun;
    }
    
    /**
     * This method returns the default HTTP page.
     * @return the default HTTP page.
     */
    public String getHttpDefaultPage() {
        return httpDefaultPage;
    }

    private void setHttpDefaultPage(String httpDefaultPage) {
        this.httpDefaultPage = httpDefaultPage;
    }

    /**
     * This method gets the HTTP port number.
     * @return The HTTP port number.
     */
    public int getHttpPort() {
        return httpPort;
    }

    private void setHttpPort(int httpPort) {
        this.httpPort = httpPort;
    }

    /**
     * This method gets the root path for HTTP requests.
     * @return Root path for HTTP requests.
     */
    public String getHttpRootPath() {
        return httpRootPath;
    }

    private void setHttpRootPath(String httpRootPath) {
       try {
            this.httpRootPath = new File(httpRootPath).getCanonicalPath();
        } catch (IOException ex) {
            logger.warning(ex.getMessage());
        }
    }

    /**
     * This method gets the default page for the HTTPS module.
     * @return The default HTTPS page.
     */
    public String getHttpsDefaultPage() {
        return httpsDefaultPage;
    }

    private void setHttpsDefaultPage(String httpsDefaultPage) {
        this.httpsDefaultPage = httpsDefaultPage;
    }

    /**
     * This method gets the HTTPS port number.
     * @return HTTPS port number.
     */
    public int getHttpsPort() {
        return httpsPort;
    }

    private void setHttpsPort(int httpsPort) {
        this.httpsPort = httpsPort;
    }

    /**
     * This method gets the root path for HTTPS requests.
     * @return The root path for HTTPS requests.
     */
    public String getHttpsRootPath() {
        return httpsRootPath;
    }

    private void setHttpsRootPath(String httpsRootPath) {
        try {
            this.httpsRootPath = new File(httpsRootPath).getCanonicalPath();
        } catch (IOException ex) {
            logger.warning(ex.getMessage());
        }
    }

    /**
     * This method gets the PHP processor's path .
     * @return PHP's path.
     */
    public String getPhpPath() {
        return phpPath;
    }

    private void setPhpPath(String phpPad) {
        this.phpPath = phpPad;
    }

    /**
     * Public constructor for loading HTTPDragonwill with settings.
     * @param HTTPRun True or false.
     * @param HTTProotPad String containing the HTTP root path.
     * @param HTTPdefaultPagina String containing the default index page for HTTP requests.
     * @param HTTPpoort HTTP's port number.
     * @param HTTPSRun True or false.
     * @param HTTPSrootPad String containing the HTTPS root path.
     * @param HTTPSdefaultPagina String containing the default index page for HTTPS requests.
     * @param HTTPSpoort HTTPS's port number.
     * @param HTTPSkeyFile SSL key file.
     * @param PHPRun True or false.
     * @param phpPad PHP processor's path.
     */
    public ServerConfig(boolean HTTPRun, String HTTProotPad, String HTTPdefaultPagina, int HTTPpoort,boolean HTTPSRun,String HTTPSrootPad, String HTTPSdefaultPagina, int HTTPSpoort, String HTTPSkeyFile, boolean PHPRun,String phpPad) {
            setHttpRun(HTTPRun);
            setHttpRootPath(HTTProotPad);
            setHttpDefaultPage(HTTPdefaultPagina);
            setHttpsRun(HTTPSRun);
            setHttpPort(HTTPpoort);
            setHttpsRootPath(HTTPSrootPad);
            setHttpsDefaultPage(HTTPSdefaultPagina);
            setHttpsPort(HTTPSpoort);
            setHttpsPrivateKey(HTTPSkeyFile);
            setPhpRun(PHPRun);
            setPhpPath(phpPad);
    }
}
